layui.use(['layer', 'form', 'table', 'ztree', 'laydate', 'admin', 'ax'], function () {
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ZTree = layui.ztree;
    var $ax = layui.ax;
    var laydate = layui.laydate;
    var admin = layui.admin;

    /**
     * 系统管理--用户管理
     */
    var money = {
        tableId: "moneyTable",    //表格id
        condition: {
            name: "",
            deptId: "",
            timeLimit: ""
        }
    };

    /**
     * 初始化表格的列
     */
    money.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, sort: true, title: '用户id'},
            {field: 'nickname', sort: true, title: '姓名'},
            {field: 'avatar', sort: true, title: '头像',templet: '<div><img src="{{d.avatar}}"></div>'},
            {field: 'mobile', sort: true, title: '手机'},
            {field: 'gender', sort: true, templet: '#genderTpl', title: '性别'},
            {field: 'address', sort: true, templet: '#addressTpl', title: '地址',templet:'<div><span class="city"></span></div>'},
            {field: 'created', sort: true, title: '注册时间'},
            {field: 'logged', sort: true, title: '最后登录时间'},
            {field: 'status', sort: true, templet: '#statusTpl', title: '状态'},
            {field: 'usergrade', sort: true, templet: '#usergradeTpl', title: '会员等级'},
            {field: 'amount_s', sort: true, title: '提现积分'}
        ]];
    };

    /**
     * 点击查询按钮
     */
    money.search = function () {
        var queryData = {};
        queryData['nickname'] = $("#nickname").val();
        queryData['mobile'] = $("#mobile").val();
        queryData['status'] = $("#status input[name='status']:checked").val();
        table.reload(money.tableId, {where: queryData});
    };


    // 渲染表格
    var tableResult = table.render({
        elem: '#' + money.tableId,
        url: Feng.ctxPath + '/user/list',
        page: true,
        height: "full-158",
        cellMinWidth: 100,
        cols: money.initColumn(),
        done: function(res){
            x(res.data);
        }

    });

    function x(d) {
        for (var i=0;i<d.length;i++){
            var a=d[i].address;
            var obj = eval("("+a+")");
            var str=obj.cityName+obj.countyName+obj.detailInfo;
            $(".city").eq(i).html(str);
        }};

    // 导出excel
    $('#btnExp').click(function () {
        money.exportExcel();
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        money.search();
    });

    // 查询是否冻结单选按钮点击事件
    $('#status').click(function () {
        money.search();
    });
});
